package com.example.firststory;


import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.ImageView;


public class InicioSlidePageFragment extends Fragment {
	
	final private static String BACKGROUND ="imagen";
	
	private int imagen;
	
	private ImageView ivImagen;
	
	
	public static InicioSlidePageFragment newInstance(int resource){
		
		InicioSlidePageFragment fragment = new InicioSlidePageFragment();
		
		Bundle extra = new Bundle();
		extra.putInt(BACKGROUND, resource);
		fragment.setArguments(extra);
		fragment.setRetainInstance(true);
		
		return fragment;
	}
	
	public void onCreate(Bundle savedInstanceState){

		super.onActivityCreated(savedInstanceState);
		
		this.imagen = (getArguments() != null) ? 
				getArguments().getInt(BACKGROUND): R.drawable.nombre;
				
	}
	
	public View onCreateView(LayoutInflater inflater,
			ViewGroup container,
			Bundle savedInstanceState){
		
		ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_inicio, container, false);
		
		ivImagen = (ImageView) rootView.findViewById(R.id.imagen);
		
		ivImagen.setImageResource(imagen);
			
		return rootView;
		
	}
	
	public void setImage(Drawable dr){
		
		
		ivImagen.setImageDrawable(dr);
		
	}
	
}

